﻿
--|--------------------------------------------------------------------------------
--| [GetLastGPSPointByGameID] - Insert Procedure Script for GPSPoint
--|--------------------------------------------------------------------------------
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id (N'[dbo].[GetGPSPointsByGameIDAndEntityID]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1) 
  DROP PROCEDURE [dbo].[GetGPSPointsByGameIDAndEntityID]
GO

CREATE PROCEDURE [dbo].[GetGPSPointsByGameIDAndEntityID]
(
	@GameID int,
	@EntityID int,
	@StartDate datetime,
	@EndDate datetime
)
AS
	SET NOCOUNT ON
	
	SELECT
		[EntityID] as ID,
		[EntityName] as [Name],
		[Latitude],
		[Longitude],
		[Time],
		[Speed],
		[Altitude],
		Datediff(s,P.[Time], GetDate()) as Delay
	FROM [GPSPoint] P
	WHERE
		P.[GameID] = 1
		AND P.[EntityID] = 1
		AND P.[Time] BETWEEN @StartDate AND @EndDate
	ORDER BY P.[Time]


GO

